package com.lyb.server.hb.demo;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import com.lyb.server.hb.utils.ConverterUtil;
import com.lyb.server.hb.utils.RSAUtil;

import java.util.HashMap;
import java.util.Map;


/**
 * Demo示例
 * @author Administrator
 *
 */
public class ApiDemo {

//	private static final String url = "http://127.0.0.1:9901/order/api";//请求地址
private static final String url = "https://mamipay.com/api-order-receipt/order/api";//请求地址--测试
//	private static final String url = "https://pay.erpyt.com/api-order-receipt/order/api";//请求地址--生产

	
	// 加密验签的公钥--测试
	private static final String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDWQWY3KvQ9iBfUHQTF2L5YQsaDR+pWJ/3dOoMuXr6rQ3qQSHxssYl6FLjmMBJ6LxVEDRnA+K81lm1QPHEs5cirF2MfJ0Een2OoNG3iDk3VIcfAVZyPwBKHct9RjM95t3mr6g0WsLxnTsWZ0mQuEdS20KYkk2uGFG4zrd/NFnB3HQIDAQAB";
	// 签名解密的私钥--测试
	private static final String privateKey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBANZBZjcq9D2IF9QdBMXYvlhCxoNH6lYn/d06gy5evqtDepBIfGyxiXoUuOYwEnovFUQNGcD4rzWWbVA8cSzlyKsXYx8nQR6fY6g0beIOTdUhx8BVnI/AEody31GMz3m3eavqDRawvGdOxZnSZC4R1LbQpiSTa4YUbjOt380WcHcdAgMBAAECgYAo0qcuJcIJo0+e+7R4GfcSjA6U3vP4XIBTUZ3DDQxZR28n5JfIgf9GwoIEYe5zV1s+7xwUF44SsMm9Ovb5bgLQtU9w28VPepEQ4p2dgx1dFU8lCnmewVCuGTaxAwvRL9DNfa++PxXiLZBrXcNykcW+0/iH gF7+dt1qgKGHnzbTgQJBAO2WvZU7x3/Cn5JEQJHDFJ+4RTfwB4ySl8GLTR37G3+E tAADA+W5Uz1l/C6CJKPMCp6iyyGgD+/twekRJFKKVeECQQDm28YvwSsW1+LQpjw3 Kwb6UQl24dSsJB92g6Mjl90mWLN4hMuyrJ5xTrQgWaz8H0C2dvzXktxYNWGsnXNtERC9AkASOz//BKBRcHjYO36M8OBTRUuieDvMEK+ufWcEhvFcPq2lVpXk+eymSH4qf3gaTZz/AVT/Fo5ChgccQGF+J/lhAkA49bzeh4DEMBwMcxekXP9pv5jgNjQtDPSeXzhfTdcI4RXXBJzlxuWI+2xCFx4xTty+qHkWD2xCb1lcJ7UVEgLZAkAYT3zyA5jc0/fdLnYCYF3457WPJr4hlbv5S2RGDrRi+v5dlbD1OJQbVmCEdetkaCBIiehDIkatqMITTctnJZQL";

	private static String idNo = "888888";//厂商识别号
	private static String merchantCode = "HB_M202303050001";//商户标识
	private static String appId = "wx0db32e374d18dc08";//微信公众号appId
	private static String appletsAppId = "wx0db32e374d18dc08";//微信小程序appId


	public static void main(String[] args) throws Exception {

//		getPublicKey();//获取系统公钥
		webPay();//JSAPI支付
//		scanPay();//付款码支付
//		scanPay();//付款码支付
//		appletsPay();//微信小程序支付
//		h5Pay();//手机h5支付
//		queryPay();//订单查询
//		refundPay();//订单交易退款
		blankPayUrl();//空白页支付

		System.out.println("main方法执行完成...");
	}


	/**
	 * 获取系统公钥(航邦公钥)
	 * 公钥是不变的,获取后请自行保存
	 * @throws Exception
	 */
	public static String getPublicKey() {
		return "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCW/wjsXggreZyibnATDIzRacKLet4PiN5aAYxWcq+Jx/jN1kULBZDGmmhN89AvTQaHayuuyqHV98KwEcRz4iRl7gF8kssS3fpWgIVJIAk4riewUTIy89s1ZZ8KTzaUTtUN/z0+34PI3VrEOvB9bOVixdPbuiuV18Q1re2gOLLyZQIDAQAB";

//		Map<String, Object> param = new HashMap<>();
//		String res = HttpUtil.post(url+"/get_public_key", param, 60000);
//		JSONObject resJsonStr = ConverterUtil.toJSON(res);
//		System.out.println("=============《获取系统公钥 响应数据》==============\n"+resJsonStr);
//		/**
//		 * 响应示例
//		 * {"code":"0000","msg":"success","data":"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiSecPJOQnhaepE1v1lTfUdW5paAbO37Ff9G6GeN25REikHYqKKW1aRNYXfrhLpty8oRcOZWd98Im7o/kQDKpcemlsRkgqRvqOqaEyy8DFNRXR0kJ9wTPafgjho/GN71K3G9uHhWTX3ejbdW5s37a60t/7Cv0utatRs1TLpiFMBFULEFYcEDGuwuTUASSORRH6ymcxHDdUb+Tc0S0AZIg7zdS7cKqNsuZAPglBLgZZOAtU/xgERSrkInCvXh/V/1AYG96jTCQ0+Ky/kXFzd+p8r21E+HGm9rNP3kcMhOWaBYi39zE2Bw31DojE4PMShY08tYZqT0nOIiLoZypLnrQ5wIDAQAB","sign":""}
//		 */
//		return (String) resJsonStr.get("data");
	}


	/**
	 * JSAPI支付
	 * @throws Exception
	 */
	public static void webPay() throws Exception{
		JSONObject jsonParams = new JSONObject();
		JSONObject data = new JSONObject();
		data.put("idNo", idNo);//厂商识别号
		data.put("merchantCode", merchantCode);//商户标识
		data.put("payEntrance", 2);//入口标识
		data.put("outTradeNo", System.currentTimeMillis());//商户订单号（由api接口调用方传入，唯一不可重复，不能为空）
		data.put("price", "0.02");//订单金额
		data.put("payWay", "1");//支付方式 1微信 2支付宝 3银联
		data.put("appId", appId);//微信appid
		data.put("openId", "orMzm6O0nD8bWhkK19hc_UhazR30");//付款人微信openId/付款人支付宝userId
		data.put("clientIp","202.99.166.4");//客户ip(付款人)
//		data.put("openId", "2088912601540952");//微信openId/支付宝userId
		data.put("outNotifyUrl", "http://116.131.181.58:8080/api/order_callback");//异步通知回调地址
		data.put("remarks", "");//订单备注
		data.put("attach", "");//附加字段 原样返回

		System.out.println("data序列化后:"+data.toString());
		String sign = RSAUtil.sign(data.toString(), privateKey);//使用自己的私钥进行签名
		System.out.println("sign签名：\n" + sign);
		jsonParams.put("data", data.toString());
		jsonParams.put("sign", sign);
		//使用系统公钥(航邦公钥)加密
		String encryptBody = RSAUtil.encrypt(jsonParams.toString(), getPublicKey());
		Map<String, Object> param = new HashMap<>();
		param.put("param", encryptBody);
		String res = HttpUtil.post(url+"/webPay", param, 60000);
		JSONObject resJson = ConverterUtil.toJSON(res);
		System.out.println("=============《响应数据》==============\n"+resJson);
		if("0000".equals(resJson.get("code")) && resJson.get("data")!=null){
			String encryptDataStr = resJson.get("data").toString();//加密的data数据
			String sign2 = resJson.get("sign").toString();//签名串
			//使用自己的私钥进行解密数据   注: 数据传输时 “+” 号会替换为空格， 解密时 需把空格替换回“+”号
			String paramJsonStr = RSAUtil.decrypt(encryptDataStr.replaceAll(" ", "+"), privateKey);
			System.out.println("解密后的data\n"+paramJsonStr);
			/**
			 * 解密后的data示例
			 * 前端根据此返回值唤起支付
			 * {"id":"1639431565536198657","payChannel":"2","orderNo":"HB2023032508583900000010","transactionId":null,"price":0.02,"payTime":null,"payWay":2,"tradeState":1,"jsapiResponse":null,"payUrl":"https://qr.alipay.com/bax0563584mdloefr4u0308e","payHtml":null,"tradeNo":"3140123032524418800108"}
			 * 若payUrl有值，则优先用tradeNo支付，若tradeNo无值，则用payUrl支付*/
			//将解密出来的数据使用系统公钥(航邦公钥)进行验签
			boolean verify = RSAUtil.verifySign(paramJsonStr, sign2, getPublicKey());
			System.out.println("验签结果："+verify);
		}
	}

	/**
	 * 空白页支付
	 * (C扫B 网页支付,JSAPI支付)
	 * 返回值为重定向页面url,前端重定向到此页面完成支付
	 */
	public static void blankPayUrl() throws Exception {
		JSONObject jsonParams = new JSONObject();
		JSONObject data = new JSONObject();
		data.put("idNo", idNo);//厂商识别号
		data.put("merchantCode", merchantCode);//商户标识
		data.put("outTradeNo", System.currentTimeMillis());//商户订单号（由api接口调用方传入，唯一不可重复，不能为空）
		data.put("price", "0.02");//订单金额
		data.put("payWay", "1");//支付方式 1微信 2支付宝 3银联
		data.put("outNotifyUrl", "http://116.131.181.58:8080/api/order_callback");//异步通知回调地址
		data.put("remarks", "");//订单备注
		data.put("attach", "");//附加字段 原样返回
		//微信点金小票微信支付用可不传

		JSONObject dotmore = new JSONObject();
		dotmore.put("title","测试"); //标题
		dotmore.put("content","测试一哈");//内容
		data.put("dotmoreContent",dotmore.toJSONString());//小票内容
		data.put("dotmoreUrl", "https://mamipay.com/web/version1.html");//点金跳转-商户自定义展示页面

		System.out.println("data序列化后:"+data.toString());
		String sign = RSAUtil.sign(data.toString(), privateKey);//使用自己的私钥进行签名
		System.out.println("sign签名：\n" + sign);
		jsonParams.put("data", data.toString());
		jsonParams.put("sign", sign);
		//使用系统公钥(航邦公钥)加密
		String encryptBody = RSAUtil.encrypt(jsonParams.toString(), getPublicKey());
		Map<String, Object> param = new HashMap<>();
		param.put("param", encryptBody);
		String res = HttpUtil.post(url+"/blankPayUrl", param, 60000);;
		JSONObject resJson = ConverterUtil.toJSON(res);
		System.out.println("=============《响应数据》==============\n"+resJson);
		if("0000".equals(resJson.get("code")) && resJson.get("data")!=null){
			String encryptDataStr = resJson.get("data").toString();//加密的data数据
			String sign2 = resJson.get("sign").toString();//签名串
			//使用自己的私钥进行解密数据   注: 数据传输时 “+” 号会替换为空格， 解密时 需把空格替换回“+”号
			String paramJsonStr = RSAUtil.decrypt(encryptDataStr.replaceAll(" ", "+"), privateKey);
			System.out.println("解密后的data\n"+paramJsonStr);
			/**
			 * 解密后的data示例
			 * 对接方后端根据这个重定向url使前端页面重定向到此url完成支付
			 * {"redirectUrl":"http://127.0.0.1:9901/web/pay/blank.html?tk=aad02bfcb9964c4c9a18e8fa83fbc5a1"}
			 **/
			//将解密出来的数据使用系统公钥(航邦公钥)进行验签
			boolean verify = RSAUtil.verifySign(paramJsonStr, sign2, getPublicKey());
			System.out.println("验签结果："+verify);
		}
	}
	/**
	 * 付款码支付
	 * @throws Exception
	 */
	public static void scanPay() throws Exception{
		JSONObject jsonParams = new JSONObject();
		JSONObject data = new JSONObject();
		data.put("idNo", idNo);//厂商识别号
		data.put("merchantCode", merchantCode);//商户标识
		data.put("payEntrance", 2);//入口标识
		data.put("outTradeNo", System.currentTimeMillis());//商户订单号（由api接口调用方传入，唯一不可重复，不能为空）
		data.put("price", "0.02");//订单金额
		data.put("authCode", "132517358594441927");//付款码
		data.put("clientIp","114.114.114.114");//客户ip(付款人)
		data.put("outNotifyUrl", "http://116.131.181.58:8080/api/order_callback");//异步通知回调地址
		data.put("remarks", "");//订单备注
		data.put("attach", "");//附加字段 原样返回
		data.put("cashierId", "1632229482443108354");//收银员id,为空则使用默认收银员
		//参与单品营销时,需传递如下属性(非必填)
		/**
		 * 	商品信息json说明
		 * 		cost_price：订单原价(分); 非必填
		 * 		receipt_id：商品小票ID; 非必填
		 * 		goods_detail：单品信息,使用Json数组格式提交;必填
		 * 			goods_id：商品编码; 必填
		 * 			goods_name: 商品名称; 必填
		 * 			quantity：商品数量; 必填
		 * 			price: 商品单价(分); 必填
		 *
		 *
		 * 	商品信息json示例
		 {
		 "cost_price":608800,
		 "receipt_id":"wx123",
		 "goods_detail":[
		 {
		 "goods_id":"商品编码",
		 "wxpay_goods_id":"1001",
		 "goods_name":"",
		 "quantity":1,
		 "price":528800
		 },
		 {
		 "goods_id":"商品编码",
		 "wxpay_goods_id":"1002",
		 "goods_name":"iPhone6s 32G",
		 "quantity":1,
		 "price":608800
		 }
		 ]
		 }
		 */
		data.put("goodsDetail", ""); //商品信息json字符串,注意嵌套格式

		String sign = RSAUtil.sign(data.toString(), privateKey);//使用自己的私钥进行签名
		System.out.println("sign签名：\n" + sign);
		jsonParams.put("data", data.toString());
		jsonParams.put("sign", sign);
		//使用系统公钥(航邦公钥)加密
		String encryptBody = RSAUtil.encrypt(jsonParams.toString(), getPublicKey());
		Map<String, Object> param = new HashMap<>();
		param.put("param", encryptBody);
		String res = HttpUtil.post(url+"/scanPay", param, 60000);
		JSONObject resJson = ConverterUtil.toJSON(res.toString());
		System.out.println("=============《响应数据》==============\n"+resJson);
		if("0000".equals(resJson.get("code")) && resJson.get("data")!=null){
			String encryptDataStr = resJson.get("data").toString();//加密的data数据
			String sign2 = resJson.get("sign").toString();//签名串
			//使用自己的私钥进行解密数据   注: 数据传输时 “+” 号会替换为空格， 解密时 需把空格替换回“+”号
			String paramJsonStr = RSAUtil.decrypt(encryptDataStr.replaceAll(" ", "+"), privateKey);
			System.out.println("解密后的data\n"+paramJsonStr);
			/**
			 * data示例
			 * {"code":"0005","msg":"请出示正确的付款码"}
			 * {"id":"1629666085983326210","payChannel":"4","orderNo":"HB2023022610140700000033","price":0.01,"payTime":null,"payWay":2,"tradeState":1,"jsapiResponse":null,"payUrl":null,"payHtml":null,"tradeNo":null}
			 */
			//将解密出来的数据使用系统公钥(航邦公钥)进行验签
			boolean verify = RSAUtil.verifySign(paramJsonStr, sign2, getPublicKey());
			System.out.println("验签结果："+verify);
		}
	}

	/**
	 * 微信/支付宝小程序支付
	 * @throws Exception
	 */
	public static void appletsPay() throws Exception{
		JSONObject jsonParams = new JSONObject();
		JSONObject data = new JSONObject();
		data.put("idNo", idNo);//厂商识别号
		data.put("payEntrance", 2);//入口标识
		data.put("merchantCode", merchantCode);//商户编号
		data.put("outTradeNo", System.currentTimeMillis());//商户订单号（由api接口调用方传入，唯一不可重复，不能为空）
		data.put("price", "0.02");//订单金额
		data.put("payWay", "2");//支付方式 1微信,2支付宝
		data.put("appId", "");//微信appid
		data.put("clientIp","202.99.166.4");
//		data.put("openId", "orMzm6O0nD8bWhkK19hc_UhazR30");//微信openId/支付宝userId
		data.put("openId", "2088802251310170");//微信openId/支付宝userId
		data.put("outNotifyUrl", "");//异步通知回调地址
		data.put("remarks", "");//订单备注
		data.put("attach", "");//附加字段 原样返回

		System.out.println("data序列化后:"+data.toString());
		String sign = RSAUtil.sign(data.toString(), privateKey);//使用自己的私钥进行签名
		System.out.println("sign签名：\n" + sign);
		jsonParams.put("data", data.toString());
		jsonParams.put("sign", sign);
		//使用系统公钥(航邦公钥)加密
		String encryptBody = RSAUtil.encrypt(jsonParams.toString(), getPublicKey());
//		encryptBody = "To0gH+jVNnQoPaVGauHOcUTYADWi1jrK0c3ptgB04LNYGYROdy0G8mjbc//OOJm+A/7TcShxKavFta9yOQdImTrDWA2dhBAErsT32XtBHAlZGYyPO6TKWng7BsH9EVQ9FHvXF2cCmj4vHPvRQ0LPzFIEA9R6pdvQbjMKY0DZ2w1+UFbBJ3VKH8mqXP8g7tsuy4Dd63hY6w0UL1hx02ZIF/+yoU8f7ZJ9+UkvJuCleTYWujf5XsNh3wdODqAXQBdkDs9X+dftmTnS0If+x3sTYFiK221SQ9dI9veo9MoA8zA9ouhXvNm0ONan3STXEIvUftzUP2eHYih3XHlNWY87Y3meYQlg2LZOcykkDnW3+pIMHF1PEjSK4FCMKWZZgtkYoso0+mjo2B0t4Cf37gLoW+QnQ99vTUOxv/yo7uZrQpZc5e9AZE0A45pokxrz4to+0LoTJsTPNCkI35xrwy2FV9mxCkWapDs1sBPH1+uJ9IFy16jiSLzBgxrzPnkWZNQUlSnlk33qSG/KNS2ZAjwZ+iLKSvEXur9MHFVLDvByRqdx2uMBWtS8ysOQ31Tt2836kD1hjcMOoWBtdqEv8aDeJZ6RxL5sjkq/cIRV1wMueP6tzcYQuZD6ZorjXQflBbH7F7PFZLUcNH3NyaNUg8b7K6OnFAtMrMIhs0n540t7f09Q+t4MRhaEjUNnkCMG8Y0M4FAAmaxfDEHhq/IQgKwfqYl0lk2tnYLOrTiFNgkM77v4DCYBGgl5j7L5McfD+CUsl9hml5NySc2LJ3YhLeR11JzIgX4P4PkXX2AYfcw2lHc/ubX4NJruRvlbsFvEuHXiuZ1EzYK1LFraIPvBCLIgZg==";
		Map<String, Object> param = new HashMap<>();
		param.put("param", encryptBody);
		String res = HttpUtil.post(url+"/appletsPay", param, 60000);
		JSONObject resJson = ConverterUtil.toJSON(res.toString());
		System.out.println("=============《响应数据》==============\n"+resJson);
		if("0000".equals(resJson.get("code")) && resJson.get("data")!=null){
			String encryptDataStr = resJson.get("data").toString();//加密的data数据
			String sign2 = resJson.get("sign").toString();//签名串
			//使用自己的私钥进行解密数据   注: 数据传输时 “+” 号会替换为空格， 解密时 需把空格替换回“+”号
			String paramJsonStr = RSAUtil.decrypt(encryptDataStr.replaceAll(" ", "+"), privateKey);
			System.out.println("解密后的data\n"+paramJsonStr);
			/**
			 * 解密后的data示例
			 * {"id":"1631473958730149890","payChannel":"2","orderNo":"HB2023030309575700000002","transactionId":null,"price":0.02,"payTime":null,"payWay":2,"tradeState":1,"jsapiResponse":null,"payUrl":"https://qr.alipay.com/bax01757fvibh1btur4x30b5","payHtml":null,"tradeNo":"01Q230303032107023"}
			 * {"id":"1629055256468467714","payChannel":"4","orderNo":"HB2023022417465400000094","price":0.01,"payTime":null,"payWay":2,"tradeState":1,"jsapiResponse":{"appId":null,"timeStamp":null,"nonceStr":null,"packages":"","signType":null,"paySign":null,"prepayId":null,"partnerid":null},"payUrl":null,"payHtml":null,"tradeNo":"2023022422001440951401518141"}
			 */
			//将解密出来的数据使用系统公钥(航邦公钥)进行验签
			boolean verify = RSAUtil.verifySign(paramJsonStr, sign2, getPublicKey());
			System.out.println("验签结果："+verify);
		}
	}

	/**
	 * 手机h5支付
	 * @throws Exception
	 */
	public static void h5Pay() throws Exception{
		JSONObject jsonParams = new JSONObject();
		JSONObject data = new JSONObject();
		data.put("idNo", idNo);//厂商识别号
		data.put("merchantCode", merchantCode);//商户编号
		data.put("payEntrance", 2);//入口标识
		data.put("outTradeNo", System.currentTimeMillis());//商户订单号（由api接口调用方传入，唯一不可重复，不能为空）
		data.put("price", "0.01");//订单金额
		data.put("payWay", "1");//支付方式 1微信 2支付宝3银联
		data.put("outNotifyUrl", "http://116.131.181.58:8080/api/order_callback");//异步通知回调地址
//		data.put("outNotifyUrl", "http://mamipay.com:18083/order/callback/hbpay_order_callback");//异步通知回调地址
		data.put("remarks", "");//订单备注
		data.put("attach", "");//附加字段 原样返回

		String sign = RSAUtil.sign(data.toString(), privateKey);//使用自己的私钥进行签名
		System.out.println("sign签名：\n" + sign);
		jsonParams.put("data", data.toString());
		jsonParams.put("sign", sign);
		//使用系统公钥(航邦公钥)加密
		String encryptBody = RSAUtil.encrypt(jsonParams.toString(), getPublicKey());
		Map<String, Object> param = new HashMap<>();
		param.put("param", encryptBody);
		String res = HttpUtil.post(url+"/h5Pay", param, 60000);
		JSONObject resJson = ConverterUtil.toJSON(res.toString());
		System.out.println("=============《响应数据》==============\n"+resJson);
		if("0000".equals(resJson.get("code")) && resJson.get("data")!=null){
			String encryptDataStr = resJson.get("data").toString();//加密的data数据
			String sign2 = resJson.get("sign").toString();//签名串
			//使用自己的私钥进行解密数据   注: 数据传输时 “+” 号会替换为空格， 解密时 需把空格替换回“+”号
			String paramJsonStr = RSAUtil.decrypt(encryptDataStr.replaceAll(" ", "+"), privateKey);
			System.out.println("解密后的data\n"+paramJsonStr);
			/**
			 * data示例
			 * {"code":"0005","msg":"请出示正确的付款码"}
			 * {"id":"1629666085983326210","payChannel":"4","orderNo":"HB2023022610140700000033","price":0.01,"payTime":null,"payWay":2,"tradeState":1,"jsapiResponse":null,"payUrl":null,"payHtml":null,"tradeNo":null}
			 */
			//将解密出来的数据使用系统公钥(航邦公钥)进行验签
			boolean verify = RSAUtil.verifySign(paramJsonStr, sign2, getPublicKey());
			System.out.println("验签结果："+verify);
		}
	}

	/**
	 * 订单查询
	 * @throws Exception
	 */
	public static void queryPay() throws Exception{
		JSONObject jsonParams = new JSONObject();
		JSONObject data = new JSONObject();
		data.put("idNo", idNo);//厂商识别号
		data.put("merchantCode", merchantCode);//商户唯一标识
		data.put("orderNo", "HB2023091110525500000001");//订单号 (orderNo和outTradeNo不可同时为空)
//		data.put("outTradeNo", "1685703461094");//商户订单号（由api接口调用方传入，唯一不可重复，不能为空）

		String sign = RSAUtil.sign(data.toString(), privateKey);//使用自己的私钥进行签名
		System.out.println("sign签名：\n" + sign);
		jsonParams.put("data", data.toString());
		jsonParams.put("sign", sign);
		//使用系统公钥(航邦公钥)加密
		String publicKey = getPublicKey();
		String encryptBody = RSAUtil.encrypt(jsonParams.toString(), publicKey);
		Map<String, Object> param = new HashMap<>();
		param.put("param", encryptBody);
		long time = System.currentTimeMillis();
		String res = HttpUtil.post(url+"/query", param, 60000);
		long endtime = System.currentTimeMillis();
		System.out.println("耗时:"+(endtime-time)+"(毫秒)");
		JSONObject resJson = ConverterUtil.toJSON(res);
		System.out.println("=============《响应数据》==============\n"+resJson);
		if("0000".equals(resJson.get("code")) && resJson.get("data")!=null){
			String encryptDataStr = resJson.get("data").toString();//加密的data数据
			String sign2 = resJson.get("sign").toString();//签名串
			//使用自己的私钥进行解密数据   注: 数据传输时 “+” 号会替换为空格， 解密时 需把空格替换回“+”号
			String paramJsonStr = RSAUtil.decrypt(encryptDataStr.replaceAll(" ", "+"), privateKey);
			System.out.println("解密后的data\n"+paramJsonStr);
			/**
			 * data示例
			 *
			 * {"code":"0006","msg":"参数错误,该订单不存在","data":"","sign":""}
			 */
			//将解密出来的数据进行验签
			boolean verify = RSAUtil.verifySign(paramJsonStr, sign2, publicKey);
			System.out.println("验签结果："+verify);
		}
	}

	/**
	 * 订单退款
	 * @throws Exception
	 */
	public static void refundPay() throws Exception{
		JSONObject jsonParams = new JSONObject();
		JSONObject data = new JSONObject();
		data.put("idNo", idNo);//厂商识别号
		data.put("merchantCode", merchantCode);//商户编号
		data.put("orderNo", "HB2023032714482000000027");//订单号 (orderNo和outTradeNo不可同时为空)
		data.put("outNotifyUrl", "http://116.131.181.58:8080/api/order_callback");//异步通知回调地址
//		data.put("outTradeNo", "1640220019107");//商户订单号（由api接口调用方传入，唯一不可重复）
		data.put("password", "123456");//此项为空时,退款不验证密码,否则进行密码验证(验证的密码为商户密码,非收银员密码)
		data.put("price", "0.01");//退款金额

		String sign = RSAUtil.sign(data.toString(), privateKey);//使用自己的私钥进行签名
		System.out.println("sign签名：\n" + sign);
		jsonParams.put("data", data.toString());
		jsonParams.put("sign", sign);
		//使用系统公钥(航邦公钥)加密
		String encryptBody = RSAUtil.encrypt(jsonParams.toString(), getPublicKey());
		Map<String, Object> param = new HashMap<>();
		param.put("param", encryptBody);
		String res = HttpUtil.post(url+"/refund", param,60000);
		JSONObject resJson = ConverterUtil.toJSON(res);
		System.out.println("=============《响应数据》==============\n"+resJson);
		if("0000".equals(resJson.get("code")) && resJson.get("data")!=null){
			String encryptDataStr = resJson.get("data").toString();//加密的data数据
			String sign2 = resJson.get("sign").toString();//签名串
			//使用自己的私钥进行解密数据   注: 数据传输时 “+” 号会替换为空格， 解密时 需把空格替换回“+”号
			String paramJsonStr = RSAUtil.decrypt(encryptDataStr.replaceAll(" ", "+"), privateKey);
			System.out.println("解密后的data\n"+paramJsonStr);
			/**
			 * data示例
			 * {"code":"0005","msg":"开通秒到的商户不支持当前操作"}
			 * {}
			 */
			//将解密出来的数据使用系统公钥(航邦公钥)进行验签
			boolean verify = RSAUtil.verifySign(paramJsonStr, sign2, getPublicKey());
			System.out.println("验签结果："+verify);
		}
	}

}
